package com.vcredit.creditcat.web.netcredit;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vcredit.creditcat.api.IAuthAccumulationManager;
import com.vcredit.creditcat.api.ICustManager;
import com.vcredit.creditcat.dto.AccInitDto;
import com.vcredit.creditcat.dto.AccLoginDto;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.vo.CityListVo;
import com.vcredit.creditcat.vo.FormDataVo;
import com.vcredit.creditcat.vo.QueryFormVo;
import com.vcredit.creditcat.web.app.BaseCreditCatController;
import com.vcredit.framework.annotation.InterfaceRequest;
import com.vcredit.framework.annotation.Log;

@Controller
@RequestMapping("/gjj")
public class AccCreditController extends BaseCreditCatController {
	@Reference(version = "1.0")
	private ICustManager custManager;
	
	@Reference(version = "1.0", timeout=120000)
	private IAuthAccumulationManager authAccumulationManager;
	
	@InterfaceRequest(value = "公积金/社保支持城市")
	@RequestMapping("/supportCity")
	@ResponseBody
	public CityListVo getSupportCity(HttpServletRequest request,@RequestBody @Valid QueryFormVo city) throws Exception {
		Cust cust =  custManager.findById(super.getCust(request).getCustId());
		return new CityListVo(authAccumulationManager.supportCity(cust.getLastProccessId(),city.getType()));
	}
	
	@InterfaceRequest(value = "公积金/社保表单查询")
	@RequestMapping("/queryForm")
	@ResponseBody
	public FormDataVo queryForm(HttpServletRequest request, @RequestBody @Valid QueryFormVo city) throws Exception {
		Cust cust =  custManager.findById(super.getCust(request).getCustId());
		return new FormDataVo(authAccumulationManager.queryForm(city.getCity(), cust.getLastProccessId(),city.getType()));
	}
	
	@InterfaceRequest(value = "公积金/社保初始化")
	@RequestMapping("/init")
	@ResponseBody
	public AccInitDto init(HttpServletRequest request, @RequestBody @Valid QueryFormVo city) throws Exception {
		Cust cust =  custManager.findById(super.getCust(request).getCustId());
		return authAccumulationManager.init(city.getCity(), cust.getLastProccessId(),city.getType());
	}
	
	@InterfaceRequest(value = "公积金/社保登录")
	@RequestMapping("/login")
	@ResponseBody
	@Log
	public String login(HttpServletRequest request, @RequestBody @Valid AccLoginDto param) throws Exception {
		Cust cust =  custManager.findById(super.getCust(request).getCustId());
		return (String)authAccumulationManager.login(cust.getLastProccessId(), param,param.getType(),cust.getCustIdno(), cust.getCustId());
	}
}
